//
//  BFZTableViewController.m
//  QuickCure
//
//  Created by 小灰灰 on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "BFZTableViewController.h"
#import "NetWorkDefine.h"
#import "NetWorkTool.h"
#import "BFZDataModel.h"
#import "MYTableViewCell.h"

@interface BFZTableViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSArray *dataListArray;
@property(nonatomic,strong)NSMutableArray *dataArray;
//准备一个可变数组传给cell使用
@property(nonatomic,strong)NSMutableArray *muArray;
@property(nonatomic,strong)UITableView *tableView;
@end

@implementation BFZTableViewController
-(NSMutableArray *)muArray
{
    if(!_muArray)
    {
        _muArray =[NSMutableArray array];
    }
    return _muArray;
}

-(NSArray *)dataArray
{
    if(!_dataArray)
    {
        _dataArray = [NSMutableArray array];
    }
    return  _dataArray ;
    
}

-(void)setDataListArray:(NSArray *)dataListArray
{
    
    _dataListArray = dataListArray;
    [self.tableView reloadData];
 
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView =[[UITableView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:self.tableView];
    UIView *view =[[UIView alloc] init];
    self.tableView.tableFooterView = view;
    self.navigationItem.title = @"并发症";
    //设置右边的确定按钮
    UIBarButtonItem *right =[[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightItem)];
    [self.navigationItem setRightBarButtonItem:right];
    
    
    [BFZDataModel dataListWithSuccessBlock:^(NSArray *dataArr) {
        
        self.dataListArray = dataArr;
        
    } errorBlock:^{
        
    }];
    
    [self.tableView registerClass:[MYTableViewCell class] forCellReuseIdentifier:@"cell2"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 
    return self.dataListArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
     
    cell.btn.tag = indexPath.row;
    BFZDataModel *model = self.dataListArray[indexPath.row];
    cell.model = model;
    cell.muArr = self.muArray;
    
    cell.strBlock = ^(NSMutableArray *mustr)
    {
        self.dataArray = mustr;
        
    };
     
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(void)clickRightItem
{
    if(self.dataStrBlock)
    {
        if(self.dataArray)
        {
            self.dataStrBlock(self.dataArray.copy);
 
        }
    
    }
    //返回上层控制器
    [self.navigationController popViewControllerAnimated:YES];
  
}

@end
